<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="智红的博客">
    <meta name="keyword"  content="智红">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
        linux使用mail命令发邮件 - 智红的博客
        
    </title>

    <!-- Custom CSS -->
    
<link rel="stylesheet" href="/css/aircloud.css">

    
<link rel="stylesheet" href="/css/gitment.css">

    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
<meta name="generator" content="Hexo 5.3.0"></head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> 好记性不如烂键盘呐 </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar ">
            <img src="/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>Zhihong Li</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/archive">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#linux%E4%BD%BF%E7%94%A8mail%E5%91%BD%E4%BB%A4%E5%8F%91%E9%82%AE%E4%BB%B6"><span class="toc-text">linux使用mail命令发邮件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ubuntu"><span class="toc-text">ubuntu</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#manjaro"><span class="toc-text">manjaro</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE"><span class="toc-text">配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8"><span class="toc-text">使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%97%A0%E9%82%AE%E4%BB%B6%E6%AD%A3%E6%96%87-%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E7%BB%93%E6%9D%9F%E4%BA%A4%E4%BA%92%E5%8F%AF%E6%8C%89ctrl-d"><span class="toc-text">1.无邮件正文(如果需要结束交互可按ctrl+d)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E6%9C%89%E9%82%AE%E4%BB%B6%E6%AD%A3%E6%96%87"><span class="toc-text">2.有邮件正文</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E5%B8%A6%E9%99%84%E4%BB%B6-doesn%E2%80%99t-work"><span class="toc-text">3.带附件(doesn’t work)</span></a></li></ol></li></ol></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> 好记性不如烂键盘呐 </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        linux使用mail命令发邮件
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2019-10-23 15:32:41</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/tags/#mail" title="mail">mail</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content no-indent">
        <h1 id="linux使用mail命令发邮件"><a href="#linux使用mail命令发邮件" class="headerlink" title="linux使用mail命令发邮件"></a>linux使用mail命令发邮件</h1><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><h2 id="ubuntu"><a href="#ubuntu" class="headerlink" title="ubuntu"></a>ubuntu</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install s-nail</span><br></pre></td></tr></table></figure>
<h2 id="manjaro"><a href="#manjaro" class="headerlink" title="manjaro"></a>manjaro</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo pacman -S s-nail</span><br></pre></td></tr></table></figure>
<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><p>修改/etc/mail.rc或/etc/nail.rc或/etc/s-nail.rc(Ubuntu)、/etc/mail.rc(centOS)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span> from=humble.li@evpowergroup.com smtp=<span class="string">&quot;smtp.mxhichina.com&quot;</span></span><br><span class="line"><span class="built_in">set</span> smtp-auth-user=<span class="string">&quot;humble.li@evpowergroup.com&quot;</span> smtp-auth-password=<span class="string">&quot;123456&quot;</span></span><br><span class="line"><span class="built_in">set</span> smtp-auth=login</span><br></pre></td></tr></table></figure>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><h3 id="1-无邮件正文-如果需要结束交互可按ctrl-d"><a href="#1-无邮件正文-如果需要结束交互可按ctrl-d" class="headerlink" title="1.无邮件正文(如果需要结束交互可按ctrl+d)"></a>1.无邮件正文(如果需要结束交互可按ctrl+d)</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mail -s <span class="string">&quot;测试主题&quot;</span> humble.li@evpowergroup.com</span><br></pre></td></tr></table></figure>
<h3 id="2-有邮件正文"><a href="#2-有邮件正文" class="headerlink" title="2.有邮件正文"></a>2.有邮件正文</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mail -s <span class="string">&quot;测试主题&quot;</span> humble.li@evpowergroup.com &lt; 正文文件.txt</span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;正文内容&quot;</span> | mail -s <span class="string">&quot;测试主题&quot;</span> humble.li@evpowergroup.com</span><br><span class="line">cat 正文文件.txt | mail -s <span class="string">&quot;测试主题&quot;</span> humble.li@evpowergroup.com</span><br></pre></td></tr></table></figure>
<h3 id="3-带附件-doesn’t-work"><a href="#3-带附件-doesn’t-work" class="headerlink" title="3.带附件(doesn’t work)"></a>3.带附件(doesn’t work)</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">uuencode a.txt a.txt | mail -s <span class="string">&quot;测试主题&quot;</span> humble.li@evpowergroup.com &lt; 正文文件.txt</span><br></pre></td></tr></table></figure>
        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        

        

        

        

        

    </ul>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>  Theme <a target="_blank" rel="noopener" href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

<script src="/js/index.js"></script>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




</html>
